﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Observer
{
    public delegate void OnUpdateDelegate( int i );

    /// <summary>
    /// ChangeColorFrame.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window, IUpdate
    {
        OnUpdateDelegate Update;
        ColorFrame color = new ColorFrame();
        ListColorFrame list;

        public MainWindow()
        {
            InitializeComponent();

            list = new ListColorFrame();

            color.Show();
            list.Show();

            Update += new OnUpdateDelegate( color.OnUpdate );
            Update += new OnUpdateDelegate( list.OnUpdate );
            Update += new OnUpdateDelegate( OnUpdate );

            radioButtonRed.IsChecked = true;

            list.SetUpdate( Update );
        }
   
        private void radioButtonRed_Click( object sender, RoutedEventArgs e )
        {
            Update( 1 );
        }

        private void radioButtonGreen_Click( object sender, RoutedEventArgs e )
        {
            Update( 2 );
        }

        private void radioButtonBlue_Click( object sender, RoutedEventArgs e )
        {
            Update( 3 );
        }

        private void Window_Closed( object sender, EventArgs e )
        {
            color.Close();
            list.Close();
        }

        #region IUpdate 成员

        public void OnUpdate( int i )
        {
            switch ( i )
            {
                case 1:
                    radioButtonRed.IsChecked = true;
                    break;
                case 2:
                    radioButtonGreen.IsChecked = true;
                    break;
                case 3:
                    radioButtonBlue.IsChecked = true;
                    break;
            }
        }

        #endregion
    }
}
